<?php
/**
 * Created by PhpStorm.
 * User: liu
 * Date: 17-3-8
 * Time: 上午9:06
 */

namespace Cframe;


class Session {
    private static function run(){
        if (!session_id()){
            session_start();
        }
    }

    public static function clean(){
        if (session_id()){
            session_unset();
            session_destroy();
        }
    }

    private static function switch_run($name,$arr){
        $k = isset($arr[0])?$arr[0]:'';
        $v = isset($arr[1])?$arr[1]:'';
        $str = true;
        switch ($name){
            case "set":
                if (!empty($k)){
                    if (!is_null($v)){
                        $_SESSION[$k] = $v;
                    }
                }
                break;
            case 'get':
                if (!empty($k)){
                    $str = isset($_SESSION[$k])?$_SESSION[$k]:false;
                }
                break;
            case 'del':
                if (is_null($k)){
                    session_unset();
                }elseif (!empty($k)){
                    if (isset($_SESSION[$k])){
                        unset($_SESSION[$k]);
                    }
                }
                break;
        }
        return $str;
    }

    public static function __callStatic($name, $arguments){
        static::run();
        $data = static::switch_run(strtolower($name),$arguments);
        return $data;
    }
}